﻿using System;
using System.ComponentModel;
using System.Linq;
using InvoiceInvoker.Logic;

namespace InvoiceInvoker.MvcUI.Filters
{
	public class CustomersFilter
	{
		[DisplayName("Imię, nazwisko lub nazwa firmy")]
		public string Name { get; set; }

		public Func<RegisteredCustomer, bool> GetExpression()
		{
			string name = Name ?? "";

			return customer =>
				customer.CustomerName.ToLower().Split(' ').Any(x => x.StartsWith(name.ToLower())) ||
				customer.CompanyName.ToLower().StartsWith(name.ToLower());
		}
	}
}